package com.sanji.sjmallmodule.account;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanji.sjmallapp.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by fhm on 2017/1/12.
 * 红包adapter
 */
public class RedPacketsAdapter extends BaseAdapter {
    private List<RedPacketsBean> mData;
    private Context mContex;

    public RedPacketsAdapter(List<RedPacketsBean> mData, Context mContex) {
        this.mData = mData;
        this.mContex = mContex;
    }

    public void notifyAdapter(List<RedPacketsBean> mData) {
        this.mData = mData;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vHolder = null;
        if (view == null) {
            view = LayoutInflater.from(mContex).inflate(R.layout.adapter_red_packet_item, null);
            vHolder = new ViewHolder(view);
            view.setTag(vHolder);
        } else {
            vHolder = (ViewHolder) view.getTag();
        }
        //捆绑数据
        RedPacketsBean bean = mData.get(i);
        vHolder.redPacketNumber.setText("￥" + bean.getPacketsNumber());
        vHolder.redPacketsTitle.setText(bean.getPacketsTitle());
        vHolder.remarksContent.setText(bean.getPacketRemark());
        vHolder.timeDeadlineContent.setText(bean.getTimeDeadline());
        vHolder.useConditionContent.setText(bean.getUseCondition());
        if (bean.isUse()) {
            vHolder.useStateImg.setImageResource(R.mipmap.red_packets_used);
        } else {
            vHolder.useStateImg.setImageResource(R.mipmap.red_packets_no_used);
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.red_packet_use_state_img)
        ImageView useStateImg;
        @BindView(R.id.red_packet_number)
        TextView redPacketNumber;
        @BindView(R.id.red_packets_title)
        TextView redPacketsTitle;
        @BindView(R.id.red_packets_use_condition_content)
        TextView useConditionContent;//使用条件
        @BindView(R.id.red_packets_remarks_content)
        TextView remarksContent;//备注
        @BindView(R.id.red_packets_time_deadline_content)
        TextView timeDeadlineContent;//到期日

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
